package com.wen.springcloud;

import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExample {
    public static void main(String[] args) throws InterruptedException {
        DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
            2, 4, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>()
        );

        // 提交任务
        executor.submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        // 获取线程堆栈信息
        Map<String, StackTraceElement[]> stackTraces = executor.getRunningThreadStackTraces();
        stackTraces.forEach((threadName, stackTrace) -> {
            System.out.println("Thread: " + threadName);
            for (StackTraceElement element : stackTrace) {
                System.out.println("\t" + element);
            }
        });

        executor.shutdown();
    }
}